﻿@model Cxuu.Models.ViewArticleExamine
@{
    ViewData["Title"] = await SystemConfig.GetByFieldNameAsync("SiteName");
}
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>@ViewData["Title"]</title>
    <link rel="stylesheet" href="~/lib/layui/css/layui.css">
    <link rel="stylesheet" href="~/admin/css/main.css">
    <style>
        html { zoom: 100%; width: 95%; margin: 5px auto; height: auto; }
        .cxuu-content-body { font-size: 16px; line-height: 30px; height: 30px; }
            .cxuu-content-body span { width: 80px; margin-left: 10px; }
    </style>
</head>
<body>

    <div class="layui-fluid" style="margin-bottom:50px;">
        <div class="layui-form">
            <form class="layui-form" action="" lay-filter="FormEdit">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label asp-for="Title" class="layui-form-label required"></label>
                        <div class="layui-input-block">
                            <div class="layui-form-mid layui-word-aux" style="color:black !important;font-weight:bold;font-size:14px;" id="title"></div>
                        </div>
                    </div>
                </div>
                <div id="examine-dis-status" style="display:none;">
                    <fieldset class="layui-elem-field ">
                        <legend>已经办结</legend>
                        <div class="layui-field-box">
                            <div class="layui-form-item">
                                <label class="layui-form-label required">终审办结</label>
                                <div class="layui-input-block" style="width:515px;">
                                    <div class="layui-form-mid layui-word-aux" style="color:black !important;font-weight:bold;font-size:14px;" id="examine"></div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label required">办结时间</label>
                                <div class="layui-input-block" style="width:515px;">
                                    <div class="layui-form-mid layui-word-aux" style="color:black !important;font-weight:bold;font-size:14px;" id="exatime"></div>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                </div>

                <div id="examine-dis-dis" style="display:none;">
                    <div class="layui-form-item">
                        <label class="layui-form-label required">审核人</label>
                        <div class="layui-input-block" style="width:320px;">
                            <div id="EditUser" style="color:red;"></div>
                            <select name="UserId" lay-verify="" lay-search="" id="userlistView" >
                            </select>
                            <script id="userListTpl" type="text/html">
                                 <option value="">请选择审核人</option>
                                {{#  layui.each(d.list, function(index, item){ }}
                                   <option value="{{ item.id }}">{{ item.deptName }} - {{ item.nickname }}</option>
                                {{#  }); }}
                                {{#  if(d.list.length === 0){ }}
                                  无流转
                                {{#  } }}
                            </script>
                            <div class="layui-form-mid layui-word-aux" style="width:300px;">输入一个以上中文字，系统将自动搜索匹配的人</div>
                        </div>
                        <div class="layui-form-mid layui-word-aux"></div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="saveBtn" id="saveBtn"><i class="layui-icon">&#xe605;</i>报审</button>
                        </div>
                    </div>
                </div>

                <div id="examine-dis-list" style="display:none;">
                    <fieldset class="layui-elem-field layui-field-title">
                        <legend>流转情况</legend>
                        <div class="layui-field-box">
                            <table class="layui-table" style="text-align:center;">
                                <colgroup>
                                    <col width="50">
                                    <col width="100">
                                    <col width="120">
                                    <col width="100">
                                    <col width="80">
                                    <col width="80">
                                    <col>
                                </colgroup>
                                <thead>
                                    <tr>
                                        <th>序</th>
                                        <th style="text-align:center;">报审人</th>
                                        <th style="text-align:center;">报审时间</th>
                                        <th style="text-align:center;">审核人</th>
                                        <th style="text-align:center;">状态</th>
                                        <th style="text-align:center;">通过</th>
                                        <th style="text-align:center;">审核意见</th>
                                    </tr>
                                </thead>
                                <tbody id="listView">
                                </tbody>
                            </table>
                        </div>
                    </fieldset>
                </div>
                <script id="examineList" type="text/html">
                    {{#  layui.each(d.list, function(index, item){ }}
                    <tr>
                        <td>{{ index+1 }}</td>
                        <td>{{ item.deptName }} -{{ item.nickName }}</td>
                        <td>{{ item.insertTime }}</td>
                        <td>{{ item.examine }}</td>
                        <td>
                                {{#  if(item.status == 0){ }}
                                  <b style="color:#FF5722;">未审核</b>
                                {{#  } else if(item.status==1) { }}
                                  <b style="color:#5FB878;">已审</b>
                                {{#  } }}
                        </td>
                        <td>
                                {{#  if(item.pass == 0){ }}
                                  <b style="color:#FF5722;">未通过</b>
                                {{#  } else if(item.pass==1) { }}
                                  <b style="color:#5FB878;">通过</b>
                                {{#  } else if(item.pass==2) { }}
                                  <b style="color:#1E9FFF;">已办结</b>
                                {{#  } }}
                        </td>
                        <td>{{ item.remarks }}</td>
                      </tr>
                    {{#  }); }}
                    {{#  if(d.list.length === 0){ }}
                      无流转
                    {{#  } }}
                </script>

                <input asp-for="Id" type="hidden">
                <input asp-for="Aid" type="hidden">
            </form>
        </div>
    </div>
    <script src="~/lib/jquery.min.js?v=1.12.4"></script>
    <script src="~/lib/layui/layui.js"></script>
    <script src="~/lib/cxuu-main.js"></script>
    <script>
        layui.define(function () {
            var form = layui.form, layer = layui.layer, $ = layui.jquery, element = layui.element, laytpl = layui.laytpl;

            var index = parent.layer.getFrameIndex(window.name);

            form.render();
            
            $.getJSON('GetUser', function (res) {
                var userList = res.data;
                if (userList !== null) {
                    var data = {
                        "list": userList
                    }
                    var getuserTpl = userListTpl.innerHTML, viewss = document.getElementById('userlistView');
                    laytpl(getuserTpl).render(data, function (html) {
                        viewss.innerHTML = html;
                    });
                    form.render("select");
                }
            });
            var id = getUrlParam('id');

            $.getJSON("GetExamineById?id=" + id, function (res) {
                if (res.status == 1) {
                    var data = res.data;
                    var art = res.art;
                    var myexa = res.myexa;
                    var ispost = res.isPost;//int 0 当前用户为未提交过该文件审核 1 反之  2为已经办结
                    form.val('FormEdit', {
                        Aid: data.aid,
                    });
                    $('#title').html(art.title);

                    if (data != null) {
                        form.val('FormEdit', {
                            Id: data.id,
                        });

                        if (data.pass == 2) {//已经办结
                            $('#examine-dis-status').show();
                            $('#remarks').html(data.remarks);
                            $('#examine').html(data.examine);
                            $('#exatime').html(data.exaTime);
                        } else {
                            if (ispost != 1 && data.status == 1) {//还未办结，可以继续流转
                                $('#EditUser').html("该文件未办结，还可以再次流转审核！");
                                $('#examine-dis-dis').show();
                            }
                        }

                        if (data.status != 1 && myexa != 1) {
                            $('#examine-dis-dis').show();
                            $('#EditUser').html("已向<b> " + data.examine + " </b>申请，还未审核可以修改");
                            form.val('FormEdit', {
                                UserId: data.userId,
                            });
                            form.render("select");
                        }


                        $('#examine-dis-list').show();
                        var list = res.list;
                        // 流转列表模板渲染
                        if (list !== null) {
                            var data = {
                                "list": list
                            }
                            var getTpl = examineList.innerHTML, view = document.getElementById('listView');
                            laytpl(getTpl).render(data, function (html) {
                                view.innerHTML = html;
                            });
                        }
                    } else {
                        if (owns == 1) {
                            $('#examine-dis-dis').show();
                        }
                    }
                } else {
                    layer.msg("数据加载失败");
                }
            });

            

            var dataPost = function (url, data) {
                $.post(url, data, function (res) {
                    if (res.status == 1) {
                        $("#saveBtn").hide();
                        layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                            parent.layui.table.reloadData('tableReload');
                            parent.layer.close(index);
                            
                        });
                    } else
                        layer.msg(res.msg, { icon: 2, anim: 6, time: 5000 });
                });
            }

            $('#saveBtn').click(function () {
                var field = form.val('FormEdit');
                dataPost('PostExamine', field);
                return false;
            });
        });

    </script>
</body>
</html>